<template>
  <div>
    <el-table
      :data="tableData"
      :border="true"
    >
      <el-table-column
        prop="boxId"
        label="箱唛"
        align="center"
        min-width="150"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="boxType"
        label="货箱类型"
        align="center"
        min-width="150"
      >
        <template v-slot="{row}">
          {{getBoxTypeStr(row.boxType)}}
        </template>
      </el-table-column>
      <el-table-column
        prop="containerNo"
        label="货柜编号"
        min-width="150"
        align="center"
        show-overflow-tooltip
      >
        <template v-slot="{row}">
          {{row.containerNo || row.flightNo || '-'}}
        </template>
      </el-table-column>
      <el-table-column
        :label="$t('table.ListingIDAndSKU')"
        align="center"
        min-width="150"
      >
        <template slot-scope="{row}">
          {{ $t('shipment.Not labeled') }} {{row.fromSku ? `(${row.fromSku})` : ''}}
        </template>
      </el-table-column>
      <el-table-column
        prop="toInventoryId"
        label="新产品标"
        min-width="150"
        align="center"
        show-overflow-tooltip
      >
        <template v-slot="{row}">
          <template v-if="row.toInventoryId">
            {{row.toInventoryId}}
          </template>
          <template v-else-if="row.toSuitId">
            {{row.toSku}}
          </template>
          <template v-else>
            -
          </template>
        </template>
      </el-table-column>
      <el-table-column
        prop="exGoodsNum"
        label="商品数量"
        align="center"
        min-width="150"
      ></el-table-column>
      <el-table-column
        prop="rlGoodsNum"
        label="实际贴标数量"
        align="center"
        min-width="150"
      >
        <template v-slot="{row}">
          <template v-if="data.status === 2 || row.isLabel === 1">
            <span :class="{
            'font-red': row.rlGoodsNum !== row.exGoodsNum,
            }">
              {{row.rlGoodsNum}}
            </span>
          </template>
          <template v-else>
            <el-input-number
              :step="1"
              :precision="0"
              :min="0"
              v-model="row.rlGoodsNum"
              @change="changeRow(row)"
            >
            </el-input-number>
          </template>

        </template>
      </el-table-column>
      <template v-if="data.status !== 2">
        <el-table-column
          prop="op"
          label="操作"
          align="left"
          min-width="200"
        >
          <template v-slot="{row}">
            <export-pdf-btn :row="row" @exportLabelPdf="exportLabelPdf" style="display: inline-block" class="mgr10" :ex-goods-num="row.exGoodsNum"></export-pdf-btn>
            <el-button :type="row.save ? 'warning' : 'primary'" @click="saveBatchRlGoodsNum(row)" v-if="data.status === 1 && row.isLabel === 0">
              {{ $t('common.save') }}</el-button>
          </template>
        </el-table-column>
      </template>

    </el-table>


  </div>

</template>

<script>

import ExportPdfBtn from "@/views/labelOrder/components/ExportPdfBtn.vue";
import {labelPartGoods, saveBatchRlGoodsNum} from "@/api/labelOrder";
import {getBoxTypeStr} from "@/utils/boxLabel";

export default {
  name: 'LabelOrderInfoTable1',
  components: {ExportPdfBtn},
  props: {
    tableData: {
      type: Array,
      required: true,
      default: () => []
    },
    data: {
      type: Object,
      required: true,
      default: () => {}
    }
  },
  computed: {
    chooseRow(){
      return this.dialogTable.find(item => item.suitListId === this.chooseSuitListId)
    }
  },
  data(){
    return {
      dialog: false,
      dialogTable: [],
      dialogForm: {
        id: 0,
      },
      dialogLoading: false,
      currentRow: null,
      chooseSuitListId: 0,
    }
  },
  methods: {
    getBoxTypeStr,
    chooseLabel(row){

    },
    uploadPDFSuccess(info){

    },
    changeRow(row){
      if(row.rlGoodsNum === undefined){
        row.rlGoodsNum = 0
      }
      row.rlOneStock = row.rlGoodsNum
    },
    exportLabelPdf(params){
      const id = params.id
      const num = params.num
      this.tableData.some(item=>{
        if(item.id === id){
          item.rlGoodsNum += num
          return true
        }
      })
    },
    saveBatchRlGoodsNum(row){
      const data = [];
      data.push({
        id: row.id,
        rlGoodsNum: row.rlGoodsNum,
        rlOneStock: row.rlGoodsNum,
        rlMiddleStock: 0,
      })
      saveBatchRlGoodsNum({
        data: data
      }).then(res=>{
        if(res.error === 0){
          this.$successMessage(res.message)
        }else{
          this.$errorMessage(res.message)
        }
      })
    },
    partGoodsLabel(){
      labelPartGoods()
        .then(res=>{

        })
    }

  }
}
</script>

<style scoped lang="scss">

</style>
